Skip to content

Conversation

@uyoyo0
Copy link
Contributor

@uyoyo0 uyoyo0 commented Aug 8, 2025

Modify RecurrenceDescriptor::getOpcode to handle RecurKind::FMinNum and RecurKind::FMaxNum by returning Instruction::FCmp, matching FMin/FMax.

Without these cases, querying the opcode for minNum/maxNum reductions can hit llvm_unreachable in code that inspects the recurrence kind. Also added IVDescriptorsTest.GetOpcodeForFMinMaxNum (gtest) to verify the mapping.

Uyiosa Iyekekpolor and others added 2 commits August 8, 2025 16:04
Teach getOpcode to return FCmp for FMinNum/FMaxNum. Without these cases, passes that query the opcode for minNum/maxNum reductions can hit llvm_unreachable. Add a unit test to cover both enums.
@github-actions
Copy link

github-actions bot commented Aug 8, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Aug 8, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 8, 2025

@llvm/pr-subscribers-llvm-analysis

Author: Uyiosa Iyekekpolor (uyoyo0)

Changes

Modify RecurrenceDescriptor::getOpcode to handle RecurKind::FMinNum and RecurKind::FMaxNum by returning Instruction::FCmp, matching FMin/FMax.

Without these cases, querying the opcode for minNum/maxNum reductions can hit llvm_unreachable in code that inspects the recurrence kind. Also added IVDescriptorsTest.GetOpcodeForFMinMaxNum (gtest) to verify the mapping.


Full diff: https://github.com/llvm/llvm-project/pull/152794.diff

2 Files Affected:

  • (modified) llvm/lib/Analysis/IVDescriptors.cpp (+2)
  • (modified) llvm/unittests/Analysis/IVDescriptorsTest.cpp (+9)
diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp
index 8be5de3bf356f..efb6a5e97bc2b 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -1228,6 +1228,8 @@ unsigned RecurrenceDescriptor::getOpcode(RecurKind Kind) {
     return Instruction::ICmp;
   case RecurKind::FMax:
   case RecurKind::FMin:
+  case RecurKind::FMaxNum:
+  case RecurKind::FMinNum:
   case RecurKind::FMaximum:
   case RecurKind::FMinimum:
   case RecurKind::FMaximumNum:
diff --git a/llvm/unittests/Analysis/IVDescriptorsTest.cpp b/llvm/unittests/Analysis/IVDescriptorsTest.cpp
index 453800abf9cab..bc237296a36b1 100644
--- a/llvm/unittests/Analysis/IVDescriptorsTest.cpp
+++ b/llvm/unittests/Analysis/IVDescriptorsTest.cpp
@@ -259,3 +259,12 @@ for.end:
         EXPECT_EQ(Kind, RecurKind::FMax);
       });
 }
+
+TEST(IVDescriptorsTest, GetOpcodeForFMinMaxNum) {
+  using RK = RecurKind;
+  // Ensure the "num" variants map to the same opcode as the plain ones.
+  EXPECT_EQ(RecurrenceDescriptor::getOpcode(RK::FMinNum),
+    RecurrenceDescriptor::getOpcode(RK::FMin));
+  EXPECT_EQ(RecurrenceDescriptor::getOpcode(RK::FMinNum),
+    RecurrenceDescriptor::getOpcode(RK::FMin));
+}

Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very likely to be incorrect.

There's not really a corresponding opcode and treating them the same as FMax/FMin will be incorrect. It would probably be better to update your code not to query getOpcode for those recurrence kinds.

@uyoyo0
Copy link
Contributor Author

uyoyo0 commented Aug 25, 2025

Thank you for the review and explanation.

@uyoyo0 uyoyo0 closed this Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants